<template>
    <div class="forget">
        <div class="forget_header">
            <img src="../../assets/img/back.png" alt="" @click="goBack">修改密码
        </div>
        <div class="login_form">
            <div class="userName half_border">
                <input type="password" v-model="changePswd.originPassword" placeholder="请输入原密码">
            </div>
            <div class="userName">
                <input type="password" v-model="changePswd.password" placeholder="请输入新密码">
            </div>
            <div class="login_bt" @click="doRestPassword()">确定</div>
        </div>
    </div>
</template>

<style>
    @import url("./login.css");
</style>
<script>
    import Layer from '../../assets/js/MessageBox'
    import API from '../../assets/js/API'
     import Validate from '../../assets/js/Validate'
    export default {
        data() {
            return {
                changePswd:{
                  originPassword:'',
                  password:'',
                }
            }
        },
        created() {
             window.scrollTo(0,0);
        },
        mounted() {
        },
        methods: {
            goBack() {
                this.$router.goBack()
            },
            doRestPassword(){
                if(!this.changePswd.originPassword){
                     Layer.showMsg('请输入旧密码');
                     return
                }
                if(!this.changePswd.password){
                      Layer.showMsg('请输入新密码');
                      return
                }
                if(this.changePswd.password.length<6||this.changePswd.password.length>20||(!Validate.passwordRule(this.changePswd.password))){
                      Layer.showMsg("请输入6至20位数字与字母的组合");
                      return
                }
                 this.$http.post(API.serviceDomain+API.modifyPassword,this.changePswd).then(
                   (res) => {
                     if(res.body.status == '000000'){
                       Layer.showMsg("修改成功");
                       this.$router.goBack()
                     } else {
                       Layer.showMsg(res.body.message);
                     }
                   },
                   (error) => {
                       Layer.showMsg("服务器开小差..")
                       return
                   }
                 )
            }
        }
    }
</script>
